﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rosetta.Default;

namespace Rosetta.Tests
{
    [TestClass]
    public class InputterTests
    {
        #region Public Methods

        [TestMethod]
        public void TestHelloWorldGet()
        {
            IInputter test = new TestInput();

            // Check Name
            Assert.AreEqual("Test", test.Name);

            // Check ReturnTypes
            var returnTypes = test.ReturnTypes;
            Assert.AreEqual(2, returnTypes.Length);
            Assert.IsTrue(returnTypes.Contains(typeof(string)));
            Assert.IsTrue(returnTypes.Contains(typeof(char)));

            // Check GetMethods
            Assert.AreEqual(1, test.GetMethodsByReturnType(typeof(string)).Length);

            // Check ReturnType
            Assert.AreEqual(typeof(string), test.GetMethod("HelloWorld").ReturnType);

            // Check call
            Assert.AreEqual("Hello World", test.Get<string>("HelloWorld"));
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void TestCantHaveArguments()
        {
            var test = new TestInput();

            test.GetMethodsByArgumentType(typeof(string));
        }

        #endregion

        #region Nested Types

        private sealed class TestInput : Inputter
        {
            public TestInput()
                : base("Test")
            {
                Add<string>("HelloWorld", HelloWorld);
            }

            public static string HelloWorld()
            {
                return "Hello World";
            }
        }

        #endregion
    }
}